package com.gary.spring;

import com.gary.spring.awreInit.BeanCycle1;
import com.gary.spring.awreInit.MyBean;
import com.gary.spring.awreInit.MyConfig1;
import com.gary.spring.awreInit.MyConfig2;
import com.gary.spring.bean.Bean2;
import org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationPropertiesBindingPostProcessor;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.CommonAnnotationBeanPostProcessor;
import org.springframework.context.annotation.ConfigurationClassPostProcessor;
import org.springframework.context.support.GenericApplicationContext;

/**
 * @author peng_rui
 * @date 2022/6/26
 */
@SpringBootApplication
public class AwareInitMain {
    public static void main(String[] args) {
        GenericApplicationContext context = new GenericApplicationContext();
//        context.registerBean("myBean", MyBean.class);


        System.out.println("***************@Autowired 失效");
        /*
         * @Autowired 失效
         *   在需要注依赖注入的类中，使用@Bean 注入bean工厂后处理器，导致后处理器执行失效
         *   详细流程图见 有道云笔记 SpringCloud -> @Autowired失效分析
         * 解决方案：
         *  实现Aware InitializingBean 接口 代替 依赖注入，初始化注解
         */

        context.registerBean("beanCycle1", BeanCycle1.class);
        context.registerBean(ConfigurationClassPostProcessor.class);
        context.registerBean(AutowiredAnnotationBeanPostProcessor.class);
        context.registerBean(CommonAnnotationBeanPostProcessor.class);
        context.refresh();

//        for (String name : context.getBeanDefinitionNames()) {
//            System.out.println(name);
//        }


        context.close();

    }
}
